$(function(){	
	init();
	bindFun();
});
//初始化数据
var da;
var handleType;
var contractId ;
var policyRef;
var dataList;
function init(){
	contractId=sessionStorage.contractId;
	policyRef=sessionStorage.policyRef;
	
	
	if(!contractId){
		contractId = getQueryString("contractId")
		sessionStorage.contractId=contractId;
	}
	if(!policyRef){
		policyRef  = getQueryString("policyRef");
		sessionStorage.policyRef=policyRef;
	}
	
	//初始化Oliver数据
	padMarketing.ajaxNormal(
			"/pad_marketing/note/initContent.action",
			{"contractId" :contractId},
			function(data){
				da=data;
				dataList = da.dataList;
				if(data.dataList.length!=0){
					for(var i in data.dataList){
						html="";
						html+='<p class="lh-45 font-18">';
						html+=data.dataList[i].ROWNUM;
						html+='.';
						html+=data.dataList[i].MSG;
						html+='</p>';
						$("#content").append(html);
					}
				}
				//处理数据  7210 只能线下  和列表数据
				if(data.NL7210=="Y"){
					addCheck("outline");
					html="";
					html+='<p class="lh-45 font-18">';
					html+=(data.dataList.length+1);
					html+='.';
					html+="您需要体检";
					html+='</p>';
					$("#content").append(html);
				}
				if(data.NL4003=="Y"){
					html="";
					html+='<p class="lh-45 font-18">';
					if(data.NL7210=="Y"){
						html+=(data.dataList.length+2);
					}else{
						html+=(data.dataList.length+1);
					}
					
					html+='.';
					html+="您需要重新签署声明";
					html+='</p>';
					$("#content").append(html);
				}
				$("#nextStep").html(' <button  onclick="returnUrl()" class="btn btn-primary btn-lg btn-block"><span class="icon icon-ok"></span>关闭</button>');
				//初始化NEWTOUCH数据
				/*padMarketing.ajaxNormal(
						"/pad_marketing/note/initMyContent.action",
						{"contractId" :contractId},
						function(data){
							if(data.flag=="01"){
								
							}
							//NEWTOUCH 记录的数据  01代表没处理过  00已处理过  handleType标识位
							if(data.flag=="00"){
								var result = data.result;
								if(result.allOk=="Y"){
									alertMsg("该照会已经处理",0,function(){
										returnUrl();
										return;
									});
								}
								if(result.handleWay=="online"){
									addCheck("online");
									$("#makeSure").html("您已选择处理方式");
									handleType=1;
								}else if(result.handleWay=="outline"){
									addCheck("outline",1);
									$("#makeSure").html("您已选择处理方式");
									handleType=2;
								}
							}
						}
				);	*/
			}
	);
	if(myScroll)
		myScroll.refresh();
}
//初始化点击事件
function bindFun(){
	
}
function sure(){
	if($("span[class='radio_checked']").length==0){
		alertMsg("先勾选处理方式");
		return;
	}
	var note={};
	note.handleWay=$("span[class='radio_checked']").attr("id");
	note.contractId= contractId;
	//记录NEWTUCH数据  确认SS
	padMarketing.ajaxNormal(
			"/pad_marketing/note/insertMyContent.action",
			note,
			function(data){
				returnUrl();
				return;
			}
	);
}
function next(){
	if(handleType!=1 && handleType!=2){
		if(da.NL4003=="N" && da.NL7210=="N" && dataList.length==0){
			alertMsg("该照会没有提供信件",0,function(){
				location.href="/pad_marketing/index/index.action";
				return;
			});
		}
		//代表没有处理过得 
		if($("span[class='radio_checked']").length==0){
			alertMsg("先勾选处理方式");
			return;
		}
		var note={};
		note.handleWay=$("span[class='radio_checked']").attr("id");
		note.contractId= contractId;
		//记录NEWTOUCH数据
		padMarketing.ajaxNormal(
				"/pad_marketing/note/insertMyContent.action",
				note,
				function(data){
				
				}
		);
	}
	if(da.NL4003=="Y"){
		location.href="/pad_marketing/note/quotationSign.action?contractId="+contractId+"&policyRef="+policyRef;
		return;
	}
	if(da.NL4003=="N" && da.NL7210=="N" && dataList.length!=0){
		location.href="/pad_marketing/note/noteIssue.action?url=noteContent.action&contractId="+contractId+"&policyRef="+policyRef;
		return;
	}
	if(da.NL4003=="N" && da.NL7210=="N" && dataList.length==0){
		alertMsg("该照会没有提供信件",0,function(){
			returnUrl();
			return;
		});
	}
}
//记录勾选功能
function addCheck(flag,index){
	if(flag=="online"){
		$("#online").attr("class","radio_checked disabled");
		$("#outline").attr("class","radio_nocheck disabled");
		$("#nextStep").html(' <button onclick="next()" id="next" class="btn btn-warning btn-lg btn-block"><span class="icon icon-right-circle"></span>下一步</button>');
	}else{
		$("#outline").attr("class","radio_checked disabled");
		$("#online").attr("class","radio_nocheck disabled");
		if(index==1){
			$("#nextStep").html(' <button  onclick="returnUrl()" class="btn btn-primary btn-lg btn-block"><span class="icon icon-ok"></span>关闭</button>');
		}else{
			$("#nextStep").html(' <button  onclick="returnUrl()" class="btn btn-primary btn-lg btn-block"><span class="icon icon-ok"></span>关闭</button>');
		}
	}
	$("#online").off("click");
	$("#outline").off("click");
	$("#online").removeAttr("onclick");
	$("#outline").removeAttr("onclick");
}
//勾选切换功能
function switchCheck(me){ 
	var flag = $(me).attr("id");
	if(flag=="online"){
		$("#nextStep").html(' <button  onclick="next()" id="next" class="btn btn-warning btn-lg btn-block"><span class="icon icon-right-circle"></span>下一步</button>');
	}else{
		$("#nextStep").html(' <button  onclick="sure()" class="btn btn-primary btn-lg btn-block"><span class="icon icon-ok"></span>关闭</button>');
	}
}
//返回按钮
function returnUrl (){
	var url = getQueryString("url");
	if(url==null){
		location.href="/pad_marketing/index/index.action";
		return;
	}
	location.href=url;
}
//查看pdf
function showNotePdf(){
	var signKey=contractId+"NEWTOUCH";
	$.get('/pad_marketing/main/getSign.action',{'jsonParam':JSON.stringify({signKey:signKey})},function(data){
		var pdfurl=data.address+"NBNotices?contractId="+contractId+"&partner=NEWTOUCH&sign="+data.sign;
		var param=0;
		var ifSign ="N";
		//调壳弹出新页面，参数说明：1：回调函数名称，2：要展示的地址，3：回调函数参数，4：是否需要签字
		gotoPDF('pdfRefresh',pdfurl,param,ifSign);
	});
	
}
